package com.ddpt.platform.common.util;

public class UrlUtil {


    /**
     *
     * @param url 要插入参数的url
     * @param plusParamsStr 传入code=123这样的格式
     * @return
     */
    public static String urlJoint(String url, String plusParamsStr) {
        String urlRes = null;
        if (url.contains( "?" )) {
            //已经有问号了
            if (!url.contains( "#" )) {
                urlRes = url + "&" + plusParamsStr;
            } else {
                StringBuffer sb = new StringBuffer( url );
                if (url.split( "#" )[0].contains( "?" )) {
                    sb.insert( sb.indexOf( "#" ), "&" + plusParamsStr );
                    urlRes = sb.toString();
                }else{
                    sb.insert( sb.indexOf( "#" ), "?" + plusParamsStr );
                    urlRes = sb.toString();
                }
            }
        } else {
            //如果没有问号
            if (!url.contains( "#" )) {
                urlRes = url + "?" + plusParamsStr;
            } else {
                StringBuffer sb = new StringBuffer( url );
                sb.insert( sb.indexOf( "#" ), "?" + plusParamsStr );
                urlRes = sb.toString();
            }
        }
        return urlRes;
    }

}
